package com.reefe.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.reefe.dto.ContentCatDto;
import com.reefe.entity.Result;
import com.reefe.entity.ZTreeNode;
import com.reefe.service.ContentCatService;
import com.reefe.utils.ResultUtil;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by xiao on 2018-03-08.
 */
@RestController
@RequestMapping("/content/cat")
public class ContentCatController {
    @Reference(version = "1.0.0")
    private ContentCatService contentCatServiceImpl;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<ZTreeNode> getContentByCid(@RequestParam(name="id", defaultValue="0") Long parentId){

        List<ZTreeNode> list=contentCatServiceImpl.getContentCatList(parentId);
        return list;
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result updateContentCat(ContentCatDto contentCatDto){

        contentCatServiceImpl.updateContentCat(contentCatDto);
        return new ResultUtil<Object>().setData(null);
    }


    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result addContentCat(ContentCatDto contentCatDto){

        contentCatServiceImpl.addContentCat(contentCatDto);
        return new ResultUtil<Object>().setData(null);
    }

    @RequestMapping(value = "/del/{id}",method = RequestMethod.DELETE)
    public Result deleteContentCat(@PathVariable("id") Long id){

        contentCatServiceImpl.deleteContentCat(id);
        return new ResultUtil<Object>().setData(null);
    }
}
